package com.spa.application.command.massagist;

import cn.hutool.core.collection.CollectionUtil;
import com.spa.infrastructure.exception.SpaException;
import com.spa.infrastructure.util.UrlUtil;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

@Data
public class WithdrawApplyNewCommand {

    @NotBlank(message = "银行卡姓名不能为空！")
    private String realName;

    @NotBlank(message = "银行卡号不能为空！")
    @Size(min = 10, max = 20, message = "请填写正确的银行卡号")
    private String bankNo;

    @NotBlank(message = "开户行不能为空！")
    @Size(min = 1, max = 200, message = "开户行填写长度不能超过200个字符")
    private String bankDetail;

    @NotNull(message = "开户行行号不能为空！")
    @Size(min = 10, max = 20, message = "请填写正确的开户行行号")
    private String bankNumber;

    @NotBlank(message = "银行卡照片不能为空！")
    private String bankPic;

    @NotNull(message = "提现金额不能为空！")
    private Integer amount;

    @NotNull(message = "申请类型不能为空！")
    private Integer applyType;

    private List<Long> orderIds;

    public void setBankPic(String bankPic){
        this.bankPic = UrlUtil.handleUrl(bankPic,",");
    }

    public void validate(){
        if (applyType == 2 && CollectionUtil.isEmpty(orderIds)){
            throw new SpaException("至少选择一个提现订单！");
        }
    }

}
